blob: b5d5a27b04182692cd66639405e2eecbb6a40f43 [file] [log] [blame]
Howard Hinnant8f73c632010-09-27 21:17:381// -*- C++ -*-
2//===--------------------------- atomic -----------------------------------===//
3//
4// The LLVM Compiler Infrastructure
5//
6// This file is distributed under the University of Illinois Open Source
7// License. See LICENSE.TXT for details.
8//
9//===----------------------------------------------------------------------===//
10
11#ifndef _LIBCPP_ATOMIC
12#define _LIBCPP_ATOMIC
13
14/*
15 atomic synopsis
16
17namespace std
18{
19
20// order and consistency
21
22typedef enum memory_order
23{
Howard Hinnantd1176e22010-09-28 17:13:3824 memory_order_relaxed,
25 memory_order_consume, // load-consume
26 memory_order_acquire, // load-acquire
27 memory_order_release, // store-release
28 memory_order_acq_rel, // store-release load-acquire
29 memory_order_seq_cst // store-release load-acquire
Howard Hinnant8f73c632010-09-27 21:17:3830} memory_order;
31
Howard Hinnant300c67a2012-04-11 20:14:2132template <class T> T kill_dependency(T y) noexcept;
Howard Hinnant8f73c632010-09-27 21:17:3833
34// lock-free property
35
Howard Hinnant7b9d6a82013-01-21 20:39:4136#define ATOMIC_BOOL_LOCK_FREE unspecified
Howard Hinnant8f73c632010-09-27 21:17:3837#define ATOMIC_CHAR_LOCK_FREE unspecified
38#define ATOMIC_CHAR16_T_LOCK_FREE unspecified
39#define ATOMIC_CHAR32_T_LOCK_FREE unspecified
40#define ATOMIC_WCHAR_T_LOCK_FREE unspecified
41#define ATOMIC_SHORT_LOCK_FREE unspecified
42#define ATOMIC_INT_LOCK_FREE unspecified
43#define ATOMIC_LONG_LOCK_FREE unspecified
44#define ATOMIC_LLONG_LOCK_FREE unspecified
Howard Hinnant7b9d6a82013-01-21 20:39:4145#define ATOMIC_POINTER_LOCK_FREE unspecified
Howard Hinnant8f73c632010-09-27 21:17:3846
Howard Hinnant8f73c632010-09-27 21:17:3847// flag type and operations
48
49typedef struct atomic_flag
50{
Howard Hinnant300c67a2012-04-11 20:14:2151 bool test_and_set(memory_order m = memory_order_seq_cst) volatile noexcept;
52 bool test_and_set(memory_order m = memory_order_seq_cst) noexcept;
53 void clear(memory_order m = memory_order_seq_cst) volatile noexcept;
54 void clear(memory_order m = memory_order_seq_cst) noexcept;
55 atomic_flag() noexcept = default;
Howard Hinnant8f73c632010-09-27 21:17:3856 atomic_flag(const atomic_flag&) = delete;
57 atomic_flag& operator=(const atomic_flag&) = delete;
58 atomic_flag& operator=(const atomic_flag&) volatile = delete;
59} atomic_flag;
60
Howard Hinnant4777bf22010-12-06 23:10:0861bool
Howard Hinnant300c67a2012-04-11 20:14:2162 atomic_flag_test_and_set(volatile atomic_flag* obj) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:0863
64bool
Howard Hinnant300c67a2012-04-11 20:14:2165 atomic_flag_test_and_set(atomic_flag* obj) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:0866
67bool
68 atomic_flag_test_and_set_explicit(volatile atomic_flag* obj,
Howard Hinnant300c67a2012-04-11 20:14:2169 memory_order m) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:0870
71bool
Howard Hinnant300c67a2012-04-11 20:14:2172 atomic_flag_test_and_set_explicit(atomic_flag* obj, memory_order m) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:0873
74void
Howard Hinnant300c67a2012-04-11 20:14:2175 atomic_flag_clear(volatile atomic_flag* obj) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:0876
77void
Howard Hinnant300c67a2012-04-11 20:14:2178 atomic_flag_clear(atomic_flag* obj) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:0879
80void
Howard Hinnant300c67a2012-04-11 20:14:2181 atomic_flag_clear_explicit(volatile atomic_flag* obj, memory_order m) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:0882
83void
Howard Hinnant300c67a2012-04-11 20:14:2184 atomic_flag_clear_explicit(atomic_flag* obj, memory_order m) noexcept;
Howard Hinnant8f73c632010-09-27 21:17:3885
86#define ATOMIC_FLAG_INIT see below
Howard Hinnante7385012010-10-19 16:51:1887#define ATOMIC_VAR_INIT(value) see below
Howard Hinnant8f73c632010-09-27 21:17:3888
Howard Hinnant8f73c632010-09-27 21:17:3889template <class T>
90struct atomic
91{
Howard Hinnant300c67a2012-04-11 20:14:2192 bool is_lock_free() const volatile noexcept;
93 bool is_lock_free() const noexcept;
94 void store(T desr, memory_order m = memory_order_seq_cst) volatile noexcept;
95 void store(T desr, memory_order m = memory_order_seq_cst) noexcept;
96 T load(memory_order m = memory_order_seq_cst) const volatile noexcept;
97 T load(memory_order m = memory_order_seq_cst) const noexcept;
98 operator T() const volatile noexcept;
99 operator T() const noexcept;
100 T exchange(T desr, memory_order m = memory_order_seq_cst) volatile noexcept;
101 T exchange(T desr, memory_order m = memory_order_seq_cst) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08102 bool compare_exchange_weak(T& expc, T desr,
Howard Hinnant300c67a2012-04-11 20:14:21103 memory_order s, memory_order f) volatile noexcept;
104 bool compare_exchange_weak(T& expc, T desr, memory_order s, memory_order f) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08105 bool compare_exchange_strong(T& expc, T desr,
Howard Hinnant300c67a2012-04-11 20:14:21106 memory_order s, memory_order f) volatile noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08107 bool compare_exchange_strong(T& expc, T desr,
Howard Hinnant300c67a2012-04-11 20:14:21108 memory_order s, memory_order f) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08109 bool compare_exchange_weak(T& expc, T desr,
Howard Hinnant300c67a2012-04-11 20:14:21110 memory_order m = memory_order_seq_cst) volatile noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08111 bool compare_exchange_weak(T& expc, T desr,
Howard Hinnant300c67a2012-04-11 20:14:21112 memory_order m = memory_order_seq_cst) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08113 bool compare_exchange_strong(T& expc, T desr,
Howard Hinnant300c67a2012-04-11 20:14:21114 memory_order m = memory_order_seq_cst) volatile noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08115 bool compare_exchange_strong(T& expc, T desr,
Howard Hinnant300c67a2012-04-11 20:14:21116 memory_order m = memory_order_seq_cst) noexcept;
Howard Hinnant8f73c632010-09-27 21:17:38117
Howard Hinnant300c67a2012-04-11 20:14:21118 atomic() noexcept = default;
119 constexpr atomic(T desr) noexcept;
Howard Hinnant8f73c632010-09-27 21:17:38120 atomic(const atomic&) = delete;
121 atomic& operator=(const atomic&) = delete;
122 atomic& operator=(const atomic&) volatile = delete;
Howard Hinnant300c67a2012-04-11 20:14:21123 T operator=(T) volatile noexcept;
124 T operator=(T) noexcept;
Howard Hinnant8f73c632010-09-27 21:17:38125};
126
127template <>
Howard Hinnant4777bf22010-12-06 23:10:08128struct atomic<integral>
Howard Hinnant8f73c632010-09-27 21:17:38129{
Howard Hinnant300c67a2012-04-11 20:14:21130 bool is_lock_free() const volatile noexcept;
131 bool is_lock_free() const noexcept;
132 void store(integral desr, memory_order m = memory_order_seq_cst) volatile noexcept;
133 void store(integral desr, memory_order m = memory_order_seq_cst) noexcept;
134 integral load(memory_order m = memory_order_seq_cst) const volatile noexcept;
135 integral load(memory_order m = memory_order_seq_cst) const noexcept;
136 operator integral() const volatile noexcept;
137 operator integral() const noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08138 integral exchange(integral desr,
Howard Hinnant300c67a2012-04-11 20:14:21139 memory_order m = memory_order_seq_cst) volatile noexcept;
140 integral exchange(integral desr, memory_order m = memory_order_seq_cst) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08141 bool compare_exchange_weak(integral& expc, integral desr,
Howard Hinnant300c67a2012-04-11 20:14:21142 memory_order s, memory_order f) volatile noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08143 bool compare_exchange_weak(integral& expc, integral desr,
Howard Hinnant300c67a2012-04-11 20:14:21144 memory_order s, memory_order f) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08145 bool compare_exchange_strong(integral& expc, integral desr,
Howard Hinnant300c67a2012-04-11 20:14:21146 memory_order s, memory_order f) volatile noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08147 bool compare_exchange_strong(integral& expc, integral desr,
Howard Hinnant300c67a2012-04-11 20:14:21148 memory_order s, memory_order f) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08149 bool compare_exchange_weak(integral& expc, integral desr,
Howard Hinnant300c67a2012-04-11 20:14:21150 memory_order m = memory_order_seq_cst) volatile noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08151 bool compare_exchange_weak(integral& expc, integral desr,
Howard Hinnant300c67a2012-04-11 20:14:21152 memory_order m = memory_order_seq_cst) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08153 bool compare_exchange_strong(integral& expc, integral desr,
Howard Hinnant300c67a2012-04-11 20:14:21154 memory_order m = memory_order_seq_cst) volatile noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08155 bool compare_exchange_strong(integral& expc, integral desr,
Howard Hinnant300c67a2012-04-11 20:14:21156 memory_order m = memory_order_seq_cst) noexcept;
Howard Hinnant8f73c632010-09-27 21:17:38157
Howard Hinnant4777bf22010-12-06 23:10:08158 integral
Howard Hinnant300c67a2012-04-11 20:14:21159 fetch_add(integral op, memory_order m = memory_order_seq_cst) volatile noexcept;
160 integral fetch_add(integral op, memory_order m = memory_order_seq_cst) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08161 integral
Howard Hinnant300c67a2012-04-11 20:14:21162 fetch_sub(integral op, memory_order m = memory_order_seq_cst) volatile noexcept;
163 integral fetch_sub(integral op, memory_order m = memory_order_seq_cst) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08164 integral
Howard Hinnant300c67a2012-04-11 20:14:21165 fetch_and(integral op, memory_order m = memory_order_seq_cst) volatile noexcept;
166 integral fetch_and(integral op, memory_order m = memory_order_seq_cst) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08167 integral
Howard Hinnant300c67a2012-04-11 20:14:21168 fetch_or(integral op, memory_order m = memory_order_seq_cst) volatile noexcept;
169 integral fetch_or(integral op, memory_order m = memory_order_seq_cst) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08170 integral
Howard Hinnant300c67a2012-04-11 20:14:21171 fetch_xor(integral op, memory_order m = memory_order_seq_cst) volatile noexcept;
172 integral fetch_xor(integral op, memory_order m = memory_order_seq_cst) noexcept;
Howard Hinnant8f73c632010-09-27 21:17:38173
Howard Hinnant300c67a2012-04-11 20:14:21174 atomic() noexcept = default;
175 constexpr atomic(integral desr) noexcept;
Howard Hinnant8f73c632010-09-27 21:17:38176 atomic(const atomic&) = delete;
177 atomic& operator=(const atomic&) = delete;
178 atomic& operator=(const atomic&) volatile = delete;
Howard Hinnant300c67a2012-04-11 20:14:21179 integral operator=(integral desr) volatile noexcept;
180 integral operator=(integral desr) noexcept;
Howard Hinnant8f73c632010-09-27 21:17:38181
Howard Hinnant300c67a2012-04-11 20:14:21182 integral operator++(int) volatile noexcept;
183 integral operator++(int) noexcept;
184 integral operator--(int) volatile noexcept;
185 integral operator--(int) noexcept;
186 integral operator++() volatile noexcept;
187 integral operator++() noexcept;
188 integral operator--() volatile noexcept;
189 integral operator--() noexcept;
190 integral operator+=(integral op) volatile noexcept;
191 integral operator+=(integral op) noexcept;
192 integral operator-=(integral op) volatile noexcept;
193 integral operator-=(integral op) noexcept;
194 integral operator&=(integral op) volatile noexcept;
195 integral operator&=(integral op) noexcept;
196 integral operator|=(integral op) volatile noexcept;
197 integral operator|=(integral op) noexcept;
198 integral operator^=(integral op) volatile noexcept;
199 integral operator^=(integral op) noexcept;
Howard Hinnant8f73c632010-09-27 21:17:38200};
201
202template <class T>
203struct atomic<T*>
Howard Hinnant8f73c632010-09-27 21:17:38204{
Howard Hinnant300c67a2012-04-11 20:14:21205 bool is_lock_free() const volatile noexcept;
206 bool is_lock_free() const noexcept;
207 void store(T* desr, memory_order m = memory_order_seq_cst) volatile noexcept;
208 void store(T* desr, memory_order m = memory_order_seq_cst) noexcept;
209 T* load(memory_order m = memory_order_seq_cst) const volatile noexcept;
210 T* load(memory_order m = memory_order_seq_cst) const noexcept;
211 operator T*() const volatile noexcept;
212 operator T*() const noexcept;
213 T* exchange(T* desr, memory_order m = memory_order_seq_cst) volatile noexcept;
214 T* exchange(T* desr, memory_order m = memory_order_seq_cst) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08215 bool compare_exchange_weak(T*& expc, T* desr,
Howard Hinnant300c67a2012-04-11 20:14:21216 memory_order s, memory_order f) volatile noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08217 bool compare_exchange_weak(T*& expc, T* desr,
Howard Hinnant300c67a2012-04-11 20:14:21218 memory_order s, memory_order f) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08219 bool compare_exchange_strong(T*& expc, T* desr,
Howard Hinnant300c67a2012-04-11 20:14:21220 memory_order s, memory_order f) volatile noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08221 bool compare_exchange_strong(T*& expc, T* desr,
Howard Hinnant300c67a2012-04-11 20:14:21222 memory_order s, memory_order f) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08223 bool compare_exchange_weak(T*& expc, T* desr,
Howard Hinnant300c67a2012-04-11 20:14:21224 memory_order m = memory_order_seq_cst) volatile noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08225 bool compare_exchange_weak(T*& expc, T* desr,
Howard Hinnant300c67a2012-04-11 20:14:21226 memory_order m = memory_order_seq_cst) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08227 bool compare_exchange_strong(T*& expc, T* desr,
Howard Hinnant300c67a2012-04-11 20:14:21228 memory_order m = memory_order_seq_cst) volatile noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08229 bool compare_exchange_strong(T*& expc, T* desr,
Howard Hinnant300c67a2012-04-11 20:14:21230 memory_order m = memory_order_seq_cst) noexcept;
231 T* fetch_add(ptrdiff_t op, memory_order m = memory_order_seq_cst) volatile noexcept;
232 T* fetch_add(ptrdiff_t op, memory_order m = memory_order_seq_cst) noexcept;
233 T* fetch_sub(ptrdiff_t op, memory_order m = memory_order_seq_cst) volatile noexcept;
234 T* fetch_sub(ptrdiff_t op, memory_order m = memory_order_seq_cst) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08235
Howard Hinnant300c67a2012-04-11 20:14:21236 atomic() noexcept = default;
237 constexpr atomic(T* desr) noexcept;
Howard Hinnant8f73c632010-09-27 21:17:38238 atomic(const atomic&) = delete;
239 atomic& operator=(const atomic&) = delete;
240 atomic& operator=(const atomic&) volatile = delete;
Howard Hinnant4777bf22010-12-06 23:10:08241
Howard Hinnant300c67a2012-04-11 20:14:21242 T* operator=(T*) volatile noexcept;
243 T* operator=(T*) noexcept;
244 T* operator++(int) volatile noexcept;
245 T* operator++(int) noexcept;
246 T* operator--(int) volatile noexcept;
247 T* operator--(int) noexcept;
248 T* operator++() volatile noexcept;
249 T* operator++() noexcept;
250 T* operator--() volatile noexcept;
251 T* operator--() noexcept;
252 T* operator+=(ptrdiff_t op) volatile noexcept;
253 T* operator+=(ptrdiff_t op) noexcept;
254 T* operator-=(ptrdiff_t op) volatile noexcept;
255 T* operator-=(ptrdiff_t op) noexcept;
Howard Hinnant8f73c632010-09-27 21:17:38256};
257
Howard Hinnant4777bf22010-12-06 23:10:08258
259template <class T>
260 bool
Howard Hinnant300c67a2012-04-11 20:14:21261 atomic_is_lock_free(const volatile atomic<T>* obj) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08262
263template <class T>
264 bool
Howard Hinnant300c67a2012-04-11 20:14:21265 atomic_is_lock_free(const atomic<T>* obj) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08266
267template <class T>
268 void
Howard Hinnant300c67a2012-04-11 20:14:21269 atomic_init(volatile atomic<T>* obj, T desr) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08270
271template <class T>
272 void
Howard Hinnant300c67a2012-04-11 20:14:21273 atomic_init(atomic<T>* obj, T desr) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08274
275template <class T>
276 void
Howard Hinnant300c67a2012-04-11 20:14:21277 atomic_store(volatile atomic<T>* obj, T desr) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08278
279template <class T>
280 void
Howard Hinnant300c67a2012-04-11 20:14:21281 atomic_store(atomic<T>* obj, T desr) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08282
283template <class T>
284 void
Howard Hinnant300c67a2012-04-11 20:14:21285 atomic_store_explicit(volatile atomic<T>* obj, T desr, memory_order m) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08286
287template <class T>
288 void
Howard Hinnant300c67a2012-04-11 20:14:21289 atomic_store_explicit(atomic<T>* obj, T desr, memory_order m) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08290
291template <class T>
292 T
Howard Hinnant300c67a2012-04-11 20:14:21293 atomic_load(const volatile atomic<T>* obj) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08294
295template <class T>
296 T
Howard Hinnant300c67a2012-04-11 20:14:21297 atomic_load(const atomic<T>* obj) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08298
299template <class T>
300 T
Howard Hinnant300c67a2012-04-11 20:14:21301 atomic_load_explicit(const volatile atomic<T>* obj, memory_order m) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08302
303template <class T>
304 T
Howard Hinnant300c67a2012-04-11 20:14:21305 atomic_load_explicit(const atomic<T>* obj, memory_order m) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08306
307template <class T>
308 T
Howard Hinnant300c67a2012-04-11 20:14:21309 atomic_exchange(volatile atomic<T>* obj, T desr) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08310
311template <class T>
312 T
Howard Hinnant300c67a2012-04-11 20:14:21313 atomic_exchange(atomic<T>* obj, T desr) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08314
315template <class T>
316 T
Howard Hinnant300c67a2012-04-11 20:14:21317 atomic_exchange_explicit(volatile atomic<T>* obj, T desr, memory_order m) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08318
319template <class T>
320 T
Howard Hinnant300c67a2012-04-11 20:14:21321 atomic_exchange_explicit(atomic<T>* obj, T desr, memory_order m) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08322
323template <class T>
324 bool
Howard Hinnant300c67a2012-04-11 20:14:21325 atomic_compare_exchange_weak(volatile atomic<T>* obj, T* expc, T desr) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08326
327template <class T>
328 bool
Howard Hinnant300c67a2012-04-11 20:14:21329 atomic_compare_exchange_weak(atomic<T>* obj, T* expc, T desr) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08330
331template <class T>
332 bool
Howard Hinnant300c67a2012-04-11 20:14:21333 atomic_compare_exchange_strong(volatile atomic<T>* obj, T* expc, T desr) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08334
335template <class T>
336 bool
Howard Hinnant300c67a2012-04-11 20:14:21337 atomic_compare_exchange_strong(atomic<T>* obj, T* expc, T desr) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08338
339template <class T>
340 bool
341 atomic_compare_exchange_weak_explicit(volatile atomic<T>* obj, T* expc,
342 T desr,
Howard Hinnant300c67a2012-04-11 20:14:21343 memory_order s, memory_order f) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08344
345template <class T>
346 bool
347 atomic_compare_exchange_weak_explicit(atomic<T>* obj, T* expc, T desr,
Howard Hinnant300c67a2012-04-11 20:14:21348 memory_order s, memory_order f) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08349
350template <class T>
351 bool
352 atomic_compare_exchange_strong_explicit(volatile atomic<T>* obj,
353 T* expc, T desr,
Howard Hinnant300c67a2012-04-11 20:14:21354 memory_order s, memory_order f) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08355
356template <class T>
357 bool
358 atomic_compare_exchange_strong_explicit(atomic<T>* obj, T* expc,
359 T desr,
Howard Hinnant300c67a2012-04-11 20:14:21360 memory_order s, memory_order f) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08361
362template <class Integral>
363 Integral
Howard Hinnant300c67a2012-04-11 20:14:21364 atomic_fetch_add(volatile atomic<Integral>* obj, Integral op) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08365
366template <class Integral>
367 Integral
Howard Hinnant300c67a2012-04-11 20:14:21368 atomic_fetch_add(atomic<Integral>* obj, Integral op) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08369
370template <class Integral>
371 Integral
372 atomic_fetch_add_explicit(volatile atomic<Integral>* obj, Integral op,
Howard Hinnant300c67a2012-04-11 20:14:21373 memory_order m) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08374template <class Integral>
375 Integral
376 atomic_fetch_add_explicit(atomic<Integral>* obj, Integral op,
Howard Hinnant300c67a2012-04-11 20:14:21377 memory_order m) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08378template <class Integral>
379 Integral
Howard Hinnant300c67a2012-04-11 20:14:21380 atomic_fetch_sub(volatile atomic<Integral>* obj, Integral op) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08381
382template <class Integral>
383 Integral
Howard Hinnant300c67a2012-04-11 20:14:21384 atomic_fetch_sub(atomic<Integral>* obj, Integral op) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08385
386template <class Integral>
387 Integral
388 atomic_fetch_sub_explicit(volatile atomic<Integral>* obj, Integral op,
Howard Hinnant300c67a2012-04-11 20:14:21389 memory_order m) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08390template <class Integral>
391 Integral
392 atomic_fetch_sub_explicit(atomic<Integral>* obj, Integral op,
Howard Hinnant300c67a2012-04-11 20:14:21393 memory_order m) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08394template <class Integral>
395 Integral
Howard Hinnant300c67a2012-04-11 20:14:21396 atomic_fetch_and(volatile atomic<Integral>* obj, Integral op) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08397
398template <class Integral>
399 Integral
Howard Hinnant300c67a2012-04-11 20:14:21400 atomic_fetch_and(atomic<Integral>* obj, Integral op) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08401
402template <class Integral>
403 Integral
404 atomic_fetch_and_explicit(volatile atomic<Integral>* obj, Integral op,
Howard Hinnant300c67a2012-04-11 20:14:21405 memory_order m) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08406template <class Integral>
407 Integral
408 atomic_fetch_and_explicit(atomic<Integral>* obj, Integral op,
Howard Hinnant300c67a2012-04-11 20:14:21409 memory_order m) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08410template <class Integral>
411 Integral
Howard Hinnant300c67a2012-04-11 20:14:21412 atomic_fetch_or(volatile atomic<Integral>* obj, Integral op) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08413
414template <class Integral>
415 Integral
Howard Hinnant300c67a2012-04-11 20:14:21416 atomic_fetch_or(atomic<Integral>* obj, Integral op) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08417
418template <class Integral>
419 Integral
420 atomic_fetch_or_explicit(volatile atomic<Integral>* obj, Integral op,
Howard Hinnant300c67a2012-04-11 20:14:21421 memory_order m) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08422template <class Integral>
423 Integral
424 atomic_fetch_or_explicit(atomic<Integral>* obj, Integral op,
Howard Hinnant300c67a2012-04-11 20:14:21425 memory_order m) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08426template <class Integral>
427 Integral
Howard Hinnant300c67a2012-04-11 20:14:21428 atomic_fetch_xor(volatile atomic<Integral>* obj, Integral op) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08429
430template <class Integral>
431 Integral
Howard Hinnant300c67a2012-04-11 20:14:21432 atomic_fetch_xor(atomic<Integral>* obj, Integral op) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08433
434template <class Integral>
435 Integral
436 atomic_fetch_xor_explicit(volatile atomic<Integral>* obj, Integral op,
Howard Hinnant300c67a2012-04-11 20:14:21437 memory_order m) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08438template <class Integral>
439 Integral
440 atomic_fetch_xor_explicit(atomic<Integral>* obj, Integral op,
Howard Hinnant300c67a2012-04-11 20:14:21441 memory_order m) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08442
443template <class T>
444 T*
Howard Hinnant300c67a2012-04-11 20:14:21445 atomic_fetch_add(volatile atomic<T*>* obj, ptrdiff_t op) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08446
447template <class T>
448 T*
Howard Hinnant300c67a2012-04-11 20:14:21449 atomic_fetch_add(atomic<T*>* obj, ptrdiff_t op) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08450
451template <class T>
452 T*
453 atomic_fetch_add_explicit(volatile atomic<T*>* obj, ptrdiff_t op,
Howard Hinnant300c67a2012-04-11 20:14:21454 memory_order m) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08455template <class T>
456 T*
Howard Hinnant300c67a2012-04-11 20:14:21457 atomic_fetch_add_explicit(atomic<T*>* obj, ptrdiff_t op, memory_order m) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08458
459template <class T>
460 T*
Howard Hinnant300c67a2012-04-11 20:14:21461 atomic_fetch_sub(volatile atomic<T*>* obj, ptrdiff_t op) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08462
463template <class T>
464 T*
Howard Hinnant300c67a2012-04-11 20:14:21465 atomic_fetch_sub(atomic<T*>* obj, ptrdiff_t op) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08466
467template <class T>
468 T*
469 atomic_fetch_sub_explicit(volatile atomic<T*>* obj, ptrdiff_t op,
Howard Hinnant300c67a2012-04-11 20:14:21470 memory_order m) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08471template <class T>
472 T*
Howard Hinnant300c67a2012-04-11 20:14:21473 atomic_fetch_sub_explicit(atomic<T*>* obj, ptrdiff_t op, memory_order m) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08474
475// Atomics for standard typedef types
476
Howard Hinnant6ae47052013-01-04 18:58:50477typedef atomic<bool> atomic_bool;
Howard Hinnant4777bf22010-12-06 23:10:08478typedef atomic<char> atomic_char;
479typedef atomic<signed char> atomic_schar;
480typedef atomic<unsigned char> atomic_uchar;
481typedef atomic<short> atomic_short;
482typedef atomic<unsigned short> atomic_ushort;
483typedef atomic<int> atomic_int;
484typedef atomic<unsigned int> atomic_uint;
485typedef atomic<long> atomic_long;
486typedef atomic<unsigned long> atomic_ulong;
487typedef atomic<long long> atomic_llong;
488typedef atomic<unsigned long long> atomic_ullong;
489typedef atomic<char16_t> atomic_char16_t;
490typedef atomic<char32_t> atomic_char32_t;
491typedef atomic<wchar_t> atomic_wchar_t;
492
493typedef atomic<int_least8_t> atomic_int_least8_t;
494typedef atomic<uint_least8_t> atomic_uint_least8_t;
495typedef atomic<int_least16_t> atomic_int_least16_t;
496typedef atomic<uint_least16_t> atomic_uint_least16_t;
497typedef atomic<int_least32_t> atomic_int_least32_t;
498typedef atomic<uint_least32_t> atomic_uint_least32_t;
499typedef atomic<int_least64_t> atomic_int_least64_t;
500typedef atomic<uint_least64_t> atomic_uint_least64_t;
501
502typedef atomic<int_fast8_t> atomic_int_fast8_t;
503typedef atomic<uint_fast8_t> atomic_uint_fast8_t;
504typedef atomic<int_fast16_t> atomic_int_fast16_t;
505typedef atomic<uint_fast16_t> atomic_uint_fast16_t;
506typedef atomic<int_fast32_t> atomic_int_fast32_t;
507typedef atomic<uint_fast32_t> atomic_uint_fast32_t;
508typedef atomic<int_fast64_t> atomic_int_fast64_t;
509typedef atomic<uint_fast64_t> atomic_uint_fast64_t;
510
511typedef atomic<intptr_t> atomic_intptr_t;
512typedef atomic<uintptr_t> atomic_uintptr_t;
513typedef atomic<size_t> atomic_size_t;
514typedef atomic<ptrdiff_t> atomic_ptrdiff_t;
515typedef atomic<intmax_t> atomic_intmax_t;
516typedef atomic<uintmax_t> atomic_uintmax_t;
517
Howard Hinnant8f73c632010-09-27 21:17:38518// fences
519
Howard Hinnant300c67a2012-04-11 20:14:21520void atomic_thread_fence(memory_order m) noexcept;
521void atomic_signal_fence(memory_order m) noexcept;
Howard Hinnant8f73c632010-09-27 21:17:38522
523} // std
524
525*/
526
527#include <__config>
Howard Hinnant4777bf22010-12-06 23:10:08528#include <cstddef>
529#include <cstdint>
530#include <type_traits>
Howard Hinnant8f73c632010-09-27 21:17:38531
Howard Hinnant08e17472011-10-17 20:05:10532#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnant8f73c632010-09-27 21:17:38533#pragma GCC system_header
Howard Hinnant08e17472011-10-17 20:05:10534#endif
Howard Hinnant8f73c632010-09-27 21:17:38535
Jonathan Roelofs8d86b2e2014-09-05 19:45:05536#ifdef _LIBCPP_HAS_NO_THREADS
537#error <atomic> is not supported on this single threaded system
Eric Fiselier00f4a492015-08-19 17:21:46538#endif
539#if !defined(_LIBCPP_HAS_C_ATOMIC_IMP) && !defined(_LIBCPP_HAS_GCC_ATOMIC_IMP)
540#error <atomic> is not implemented
541#endif
Jonathan Roelofs8d86b2e2014-09-05 19:45:05542
Howard Hinnant8f73c632010-09-27 21:17:38543_LIBCPP_BEGIN_NAMESPACE_STD
544
Howard Hinnantd1176e22010-09-28 17:13:38545typedef enum memory_order
546{
547 memory_order_relaxed, memory_order_consume, memory_order_acquire,
548 memory_order_release, memory_order_acq_rel, memory_order_seq_cst
549} memory_order;
550
Eric Fiselier00f4a492015-08-19 17:21:46551#if defined(_LIBCPP_HAS_GCC_ATOMIC_IMP)
Dan Alberte8b42322014-08-09 23:51:51552namespace __gcc_atomic {
Marshall Clowe4220212015-01-11 06:15:59553template <typename _Tp>
Dan Alberte8b42322014-08-09 23:51:51554struct __gcc_atomic_t {
Eric Fiseliera4ae16b2015-10-14 08:36:22555 _LIBCPP_INLINE_VISIBILITY
556#ifndef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
557 __gcc_atomic_t() _NOEXCEPT = default;
558#else
559 __gcc_atomic_t() _NOEXCEPT : __a_value() {}
560#endif // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
Eric Fiselier26edd802015-07-14 17:50:27561 _LIBCPP_CONSTEXPR explicit __gcc_atomic_t(_Tp value) _NOEXCEPT
562 : __a_value(value) {}
Marshall Clowe4220212015-01-11 06:15:59563 _Tp __a_value;
Dan Alberte8b42322014-08-09 23:51:51564};
565#define _Atomic(x) __gcc_atomic::__gcc_atomic_t<x>
566
Marshall Clowe4220212015-01-11 06:15:59567template <typename _Tp> _Tp __create();
Dan Alberte8b42322014-08-09 23:51:51568
Marshall Clowe4220212015-01-11 06:15:59569template <typename _Tp, typename _Td>
570typename enable_if<sizeof(_Tp()->__a_value = __create<_Td>()), char>::type
Dan Alberte8b42322014-08-09 23:51:51571 __test_atomic_assignable(int);
Marshall Clowe4220212015-01-11 06:15:59572template <typename _Tp, typename _Up>
Dan Alberte8b42322014-08-09 23:51:51573__two __test_atomic_assignable(...);
574
Marshall Clowe4220212015-01-11 06:15:59575template <typename _Tp, typename _Td>
Dan Alberte8b42322014-08-09 23:51:51576struct __can_assign {
577 static const bool value =
Marshall Clowe4220212015-01-11 06:15:59578 sizeof(__test_atomic_assignable<_Tp, _Td>(1)) == sizeof(char);
Dan Alberte8b42322014-08-09 23:51:51579};
580
Eric Fiseliera4ae16b2015-10-14 08:36:22581static inline _LIBCPP_CONSTEXPR int __to_gcc_order(memory_order __order) {
Dan Alberte8b42322014-08-09 23:51:51582 // Avoid switch statement to make this a constexpr.
583 return __order == memory_order_relaxed ? __ATOMIC_RELAXED:
584 (__order == memory_order_acquire ? __ATOMIC_ACQUIRE:
585 (__order == memory_order_release ? __ATOMIC_RELEASE:
586 (__order == memory_order_seq_cst ? __ATOMIC_SEQ_CST:
587 (__order == memory_order_acq_rel ? __ATOMIC_ACQ_REL:
588 __ATOMIC_CONSUME))));
589}
590
Eric Fiseliera4ae16b2015-10-14 08:36:22591static inline _LIBCPP_CONSTEXPR int __to_gcc_failure_order(memory_order __order) {
Dan Albertc1017382015-01-06 18:39:37592 // Avoid switch statement to make this a constexpr.
593 return __order == memory_order_relaxed ? __ATOMIC_RELAXED:
594 (__order == memory_order_acquire ? __ATOMIC_ACQUIRE:
595 (__order == memory_order_release ? __ATOMIC_RELAXED:
596 (__order == memory_order_seq_cst ? __ATOMIC_SEQ_CST:
597 (__order == memory_order_acq_rel ? __ATOMIC_ACQUIRE:
598 __ATOMIC_CONSUME))));
599}
600
Dan Alberte8b42322014-08-09 23:51:51601} // namespace __gcc_atomic
602
603template <typename _Tp>
604static inline
605typename enable_if<
606 __gcc_atomic::__can_assign<volatile _Atomic(_Tp)*, _Tp>::value>::type
607__c11_atomic_init(volatile _Atomic(_Tp)* __a, _Tp __val) {
608 __a->__a_value = __val;
609}
610
611template <typename _Tp>
612static inline
613typename enable_if<
614 !__gcc_atomic::__can_assign<volatile _Atomic(_Tp)*, _Tp>::value &&
615 __gcc_atomic::__can_assign< _Atomic(_Tp)*, _Tp>::value>::type
616__c11_atomic_init(volatile _Atomic(_Tp)* __a, _Tp __val) {
617 // [atomics.types.generic]p1 guarantees _Tp is trivially copyable. Because
618 // the default operator= in an object is not volatile, a byte-by-byte copy
619 // is required.
620 volatile char* to = reinterpret_cast<volatile char*>(&__a->__a_value);
621 volatile char* end = to + sizeof(_Tp);
622 char* from = reinterpret_cast<char*>(&__val);
623 while (to != end) {
624 *to++ = *from++;
625 }
626}
627
628template <typename _Tp>
629static inline void __c11_atomic_init(_Atomic(_Tp)* __a, _Tp __val) {
630 __a->__a_value = __val;
631}
632
633static inline void __c11_atomic_thread_fence(memory_order __order) {
634 __atomic_thread_fence(__gcc_atomic::__to_gcc_order(__order));
635}
636
637static inline void __c11_atomic_signal_fence(memory_order __order) {
638 __atomic_signal_fence(__gcc_atomic::__to_gcc_order(__order));
639}
640
Dan Alberte8b42322014-08-09 23:51:51641template <typename _Tp>
642static inline void __c11_atomic_store(volatile _Atomic(_Tp)* __a, _Tp __val,
643 memory_order __order) {
644 return __atomic_store(&__a->__a_value, &__val,
645 __gcc_atomic::__to_gcc_order(__order));
646}
647
648template <typename _Tp>
649static inline void __c11_atomic_store(_Atomic(_Tp)* __a, _Tp __val,
650 memory_order __order) {
Dan Albertc1017382015-01-06 18:39:37651 __atomic_store(&__a->__a_value, &__val,
652 __gcc_atomic::__to_gcc_order(__order));
Dan Alberte8b42322014-08-09 23:51:51653}
654
655template <typename _Tp>
656static inline _Tp __c11_atomic_load(volatile _Atomic(_Tp)* __a,
657 memory_order __order) {
658 _Tp __ret;
659 __atomic_load(&__a->__a_value, &__ret,
660 __gcc_atomic::__to_gcc_order(__order));
661 return __ret;
662}
663
664template <typename _Tp>
665static inline _Tp __c11_atomic_load(_Atomic(_Tp)* __a, memory_order __order) {
666 _Tp __ret;
667 __atomic_load(&__a->__a_value, &__ret,
668 __gcc_atomic::__to_gcc_order(__order));
669 return __ret;
670}
671
672template <typename _Tp>
673static inline _Tp __c11_atomic_exchange(volatile _Atomic(_Tp)* __a,
674 _Tp __value, memory_order __order) {
675 _Tp __ret;
676 __atomic_exchange(&__a->__a_value, &__value, &__ret,
677 __gcc_atomic::__to_gcc_order(__order));
678 return __ret;
679}
680
681template <typename _Tp>
682static inline _Tp __c11_atomic_exchange(_Atomic(_Tp)* __a, _Tp __value,
683 memory_order __order) {
684 _Tp __ret;
685 __atomic_exchange(&__a->__a_value, &__value, &__ret,
686 __gcc_atomic::__to_gcc_order(__order));
687 return __ret;
688}
689
690template <typename _Tp>
691static inline bool __c11_atomic_compare_exchange_strong(
692 volatile _Atomic(_Tp)* __a, _Tp* __expected, _Tp __value,
693 memory_order __success, memory_order __failure) {
694 return __atomic_compare_exchange(&__a->__a_value, __expected, &__value,
695 false,
696 __gcc_atomic::__to_gcc_order(__success),
Dan Albertc1017382015-01-06 18:39:37697 __gcc_atomic::__to_gcc_failure_order(__failure));
Dan Alberte8b42322014-08-09 23:51:51698}
699
700template <typename _Tp>
701static inline bool __c11_atomic_compare_exchange_strong(
702 _Atomic(_Tp)* __a, _Tp* __expected, _Tp __value, memory_order __success,
703 memory_order __failure) {
704 return __atomic_compare_exchange(&__a->__a_value, __expected, &__value,
705 false,
706 __gcc_atomic::__to_gcc_order(__success),
Dan Albertc1017382015-01-06 18:39:37707 __gcc_atomic::__to_gcc_failure_order(__failure));
Dan Alberte8b42322014-08-09 23:51:51708}
709
710template <typename _Tp>
711static inline bool __c11_atomic_compare_exchange_weak(
712 volatile _Atomic(_Tp)* __a, _Tp* __expected, _Tp __value,
713 memory_order __success, memory_order __failure) {
714 return __atomic_compare_exchange(&__a->__a_value, __expected, &__value,
715 true,
716 __gcc_atomic::__to_gcc_order(__success),
Dan Albertc1017382015-01-06 18:39:37717 __gcc_atomic::__to_gcc_failure_order(__failure));
Dan Alberte8b42322014-08-09 23:51:51718}
719
720template <typename _Tp>
721static inline bool __c11_atomic_compare_exchange_weak(
722 _Atomic(_Tp)* __a, _Tp* __expected, _Tp __value, memory_order __success,
723 memory_order __failure) {
724 return __atomic_compare_exchange(&__a->__a_value, __expected, &__value,
725 true,
726 __gcc_atomic::__to_gcc_order(__success),
Dan Albertc1017382015-01-06 18:39:37727 __gcc_atomic::__to_gcc_failure_order(__failure));
Dan Alberte8b42322014-08-09 23:51:51728}
729
730template <typename _Tp>
731struct __skip_amt { enum {value = 1}; };
732
733template <typename _Tp>
734struct __skip_amt<_Tp*> { enum {value = sizeof(_Tp)}; };
735
736// FIXME: Haven't figured out what the spec says about using arrays with
737// atomic_fetch_add. Force a failure rather than creating bad behavior.
738template <typename _Tp>
739struct __skip_amt<_Tp[]> { };
740template <typename _Tp, int n>
741struct __skip_amt<_Tp[n]> { };
742
743template <typename _Tp, typename _Td>
744static inline _Tp __c11_atomic_fetch_add(volatile _Atomic(_Tp)* __a,
745 _Td __delta, memory_order __order) {
746 return __atomic_fetch_add(&__a->__a_value, __delta * __skip_amt<_Tp>::value,
747 __gcc_atomic::__to_gcc_order(__order));
748}
749
750template <typename _Tp, typename _Td>
751static inline _Tp __c11_atomic_fetch_add(_Atomic(_Tp)* __a, _Td __delta,
752 memory_order __order) {
753 return __atomic_fetch_add(&__a->__a_value, __delta * __skip_amt<_Tp>::value,
754 __gcc_atomic::__to_gcc_order(__order));
755}
756
757template <typename _Tp, typename _Td>
758static inline _Tp __c11_atomic_fetch_sub(volatile _Atomic(_Tp)* __a,
759 _Td __delta, memory_order __order) {
760 return __atomic_fetch_sub(&__a->__a_value, __delta * __skip_amt<_Tp>::value,
761 __gcc_atomic::__to_gcc_order(__order));
762}
763
764template <typename _Tp, typename _Td>
765static inline _Tp __c11_atomic_fetch_sub(_Atomic(_Tp)* __a, _Td __delta,
766 memory_order __order) {
767 return __atomic_fetch_sub(&__a->__a_value, __delta * __skip_amt<_Tp>::value,
768 __gcc_atomic::__to_gcc_order(__order));
769}
770
771template <typename _Tp>
772static inline _Tp __c11_atomic_fetch_and(volatile _Atomic(_Tp)* __a,
773 _Tp __pattern, memory_order __order) {
774 return __atomic_fetch_and(&__a->__a_value, __pattern,
775 __gcc_atomic::__to_gcc_order(__order));
776}
777
778template <typename _Tp>
779static inline _Tp __c11_atomic_fetch_and(_Atomic(_Tp)* __a,
780 _Tp __pattern, memory_order __order) {
781 return __atomic_fetch_and(&__a->__a_value, __pattern,
782 __gcc_atomic::__to_gcc_order(__order));
783}
784
785template <typename _Tp>
786static inline _Tp __c11_atomic_fetch_or(volatile _Atomic(_Tp)* __a,
787 _Tp __pattern, memory_order __order) {
788 return __atomic_fetch_or(&__a->__a_value, __pattern,
789 __gcc_atomic::__to_gcc_order(__order));
790}
791
792template <typename _Tp>
793static inline _Tp __c11_atomic_fetch_or(_Atomic(_Tp)* __a, _Tp __pattern,
794 memory_order __order) {
795 return __atomic_fetch_or(&__a->__a_value, __pattern,
796 __gcc_atomic::__to_gcc_order(__order));
797}
798
799template <typename _Tp>
800static inline _Tp __c11_atomic_fetch_xor(volatile _Atomic(_Tp)* __a,
801 _Tp __pattern, memory_order __order) {
802 return __atomic_fetch_xor(&__a->__a_value, __pattern,
803 __gcc_atomic::__to_gcc_order(__order));
804}
805
806template <typename _Tp>
807static inline _Tp __c11_atomic_fetch_xor(_Atomic(_Tp)* __a, _Tp __pattern,
808 memory_order __order) {
809 return __atomic_fetch_xor(&__a->__a_value, __pattern,
810 __gcc_atomic::__to_gcc_order(__order));
811}
Eric Fiselier00f4a492015-08-19 17:21:46812#endif // _LIBCPP_HAS_GCC_ATOMIC_IMP
Dan Alberte8b42322014-08-09 23:51:51813
Howard Hinnantd1176e22010-09-28 17:13:38814template <class _Tp>
815inline _LIBCPP_INLINE_VISIBILITY
816_Tp
Howard Hinnant300c67a2012-04-11 20:14:21817kill_dependency(_Tp __y) _NOEXCEPT
Howard Hinnantd1176e22010-09-28 17:13:38818{
819 return __y;
820}
Howard Hinnant8f73c632010-09-27 21:17:38821
Howard Hinnant91e2f262010-12-07 20:46:14822// general atomic<T>
823
824template <class _Tp, bool = is_integral<_Tp>::value && !is_same<_Tp, bool>::value>
825struct __atomic_base // false
826{
Howard Hinnant7eb9f1e2012-09-16 20:33:09827 mutable _Atomic(_Tp) __a_;
Howard Hinnant91e2f262010-12-07 20:46:14828
829 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:21830 bool is_lock_free() const volatile _NOEXCEPT
Eric Fiselier7726a342015-06-13 00:23:07831 {
Eric Fiselier00f4a492015-08-19 17:21:46832#if defined(_LIBCPP_HAS_C_ATOMIC_IMP)
Eric Fiselier7726a342015-06-13 00:23:07833 return __c11_atomic_is_lock_free(sizeof(_Tp));
834#else
835 return __atomic_is_lock_free(sizeof(_Tp), 0);
836#endif
837 }
Howard Hinnant91e2f262010-12-07 20:46:14838 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:21839 bool is_lock_free() const _NOEXCEPT
Eric Fiselier7726a342015-06-13 00:23:07840 {return static_cast<__atomic_base const volatile*>(this)->is_lock_free();}
Howard Hinnant91e2f262010-12-07 20:46:14841 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:21842 void store(_Tp __d, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
Richard Smith6186c7f2012-04-11 18:55:46843 {__c11_atomic_store(&__a_, __d, __m);}
Howard Hinnant91e2f262010-12-07 20:46:14844 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:21845 void store(_Tp __d, memory_order __m = memory_order_seq_cst) _NOEXCEPT
Richard Smith6186c7f2012-04-11 18:55:46846 {__c11_atomic_store(&__a_, __d, __m);}
Howard Hinnant91e2f262010-12-07 20:46:14847 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:21848 _Tp load(memory_order __m = memory_order_seq_cst) const volatile _NOEXCEPT
Richard Smith6186c7f2012-04-11 18:55:46849 {return __c11_atomic_load(&__a_, __m);}
Howard Hinnant91e2f262010-12-07 20:46:14850 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:21851 _Tp load(memory_order __m = memory_order_seq_cst) const _NOEXCEPT
Richard Smith6186c7f2012-04-11 18:55:46852 {return __c11_atomic_load(&__a_, __m);}
Howard Hinnant91e2f262010-12-07 20:46:14853 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:21854 operator _Tp() const volatile _NOEXCEPT {return load();}
Howard Hinnant91e2f262010-12-07 20:46:14855 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:21856 operator _Tp() const _NOEXCEPT {return load();}
Howard Hinnant91e2f262010-12-07 20:46:14857 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:21858 _Tp exchange(_Tp __d, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
Richard Smith6186c7f2012-04-11 18:55:46859 {return __c11_atomic_exchange(&__a_, __d, __m);}
Howard Hinnant91e2f262010-12-07 20:46:14860 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:21861 _Tp exchange(_Tp __d, memory_order __m = memory_order_seq_cst) _NOEXCEPT
Richard Smith6186c7f2012-04-11 18:55:46862 {return __c11_atomic_exchange(&__a_, __d, __m);}
Howard Hinnant91e2f262010-12-07 20:46:14863 _LIBCPP_INLINE_VISIBILITY
864 bool compare_exchange_weak(_Tp& __e, _Tp __d,
Howard Hinnant300c67a2012-04-11 20:14:21865 memory_order __s, memory_order __f) volatile _NOEXCEPT
Richard Smith6186c7f2012-04-11 18:55:46866 {return __c11_atomic_compare_exchange_weak(&__a_, &__e, __d, __s, __f);}
Howard Hinnant91e2f262010-12-07 20:46:14867 _LIBCPP_INLINE_VISIBILITY
868 bool compare_exchange_weak(_Tp& __e, _Tp __d,
Howard Hinnant300c67a2012-04-11 20:14:21869 memory_order __s, memory_order __f) _NOEXCEPT
Richard Smith6186c7f2012-04-11 18:55:46870 {return __c11_atomic_compare_exchange_weak(&__a_, &__e, __d, __s, __f);}
Howard Hinnant91e2f262010-12-07 20:46:14871 _LIBCPP_INLINE_VISIBILITY
872 bool compare_exchange_strong(_Tp& __e, _Tp __d,
Howard Hinnant300c67a2012-04-11 20:14:21873 memory_order __s, memory_order __f) volatile _NOEXCEPT
Richard Smith6186c7f2012-04-11 18:55:46874 {return __c11_atomic_compare_exchange_strong(&__a_, &__e, __d, __s, __f);}
Howard Hinnant91e2f262010-12-07 20:46:14875 _LIBCPP_INLINE_VISIBILITY
876 bool compare_exchange_strong(_Tp& __e, _Tp __d,
Howard Hinnant300c67a2012-04-11 20:14:21877 memory_order __s, memory_order __f) _NOEXCEPT
Richard Smith6186c7f2012-04-11 18:55:46878 {return __c11_atomic_compare_exchange_strong(&__a_, &__e, __d, __s, __f);}
Howard Hinnant91e2f262010-12-07 20:46:14879 _LIBCPP_INLINE_VISIBILITY
880 bool compare_exchange_weak(_Tp& __e, _Tp __d,
Howard Hinnant300c67a2012-04-11 20:14:21881 memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
Richard Smith6186c7f2012-04-11 18:55:46882 {return __c11_atomic_compare_exchange_weak(&__a_, &__e, __d, __m, __m);}
Howard Hinnant91e2f262010-12-07 20:46:14883 _LIBCPP_INLINE_VISIBILITY
884 bool compare_exchange_weak(_Tp& __e, _Tp __d,
Howard Hinnant300c67a2012-04-11 20:14:21885 memory_order __m = memory_order_seq_cst) _NOEXCEPT
Richard Smith6186c7f2012-04-11 18:55:46886 {return __c11_atomic_compare_exchange_weak(&__a_, &__e, __d, __m, __m);}
Howard Hinnant91e2f262010-12-07 20:46:14887 _LIBCPP_INLINE_VISIBILITY
888 bool compare_exchange_strong(_Tp& __e, _Tp __d,
Howard Hinnant300c67a2012-04-11 20:14:21889 memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
Richard Smith6186c7f2012-04-11 18:55:46890 {return __c11_atomic_compare_exchange_strong(&__a_, &__e, __d, __m, __m);}
Howard Hinnant91e2f262010-12-07 20:46:14891 _LIBCPP_INLINE_VISIBILITY
892 bool compare_exchange_strong(_Tp& __e, _Tp __d,
Howard Hinnant300c67a2012-04-11 20:14:21893 memory_order __m = memory_order_seq_cst) _NOEXCEPT
Richard Smith6186c7f2012-04-11 18:55:46894 {return __c11_atomic_compare_exchange_strong(&__a_, &__e, __d, __m, __m);}
Howard Hinnant91e2f262010-12-07 20:46:14895
896 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant74f4da72013-05-02 20:18:43897#ifndef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
898 __atomic_base() _NOEXCEPT = default;
899#else
900 __atomic_base() _NOEXCEPT : __a_() {}
901#endif // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
902
Howard Hinnant91e2f262010-12-07 20:46:14903 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:21904 _LIBCPP_CONSTEXPR __atomic_base(_Tp __d) _NOEXCEPT : __a_(__d) {}
Howard Hinnant770d1c42010-12-08 17:20:28905#ifndef _LIBCPP_HAS_NO_DELETED_FUNCTIONS
Howard Hinnant91e2f262010-12-07 20:46:14906 __atomic_base(const __atomic_base&) = delete;
907 __atomic_base& operator=(const __atomic_base&) = delete;
908 __atomic_base& operator=(const __atomic_base&) volatile = delete;
Howard Hinnant770d1c42010-12-08 17:20:28909#else // _LIBCPP_HAS_NO_DELETED_FUNCTIONS
910private:
911 __atomic_base(const __atomic_base&);
912 __atomic_base& operator=(const __atomic_base&);
913 __atomic_base& operator=(const __atomic_base&) volatile;
914#endif // _LIBCPP_HAS_NO_DELETED_FUNCTIONS
Howard Hinnant91e2f262010-12-07 20:46:14915};
916
917// atomic<Integral>
918
919template <class _Tp>
920struct __atomic_base<_Tp, true>
921 : public __atomic_base<_Tp, false>
922{
923 typedef __atomic_base<_Tp, false> __base;
924 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant74f4da72013-05-02 20:18:43925 __atomic_base() _NOEXCEPT _LIBCPP_DEFAULT
Howard Hinnant91e2f262010-12-07 20:46:14926 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:21927 _LIBCPP_CONSTEXPR __atomic_base(_Tp __d) _NOEXCEPT : __base(__d) {}
Howard Hinnant91e2f262010-12-07 20:46:14928
929 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:21930 _Tp fetch_add(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
Richard Smith6186c7f2012-04-11 18:55:46931 {return __c11_atomic_fetch_add(&this->__a_, __op, __m);}
Howard Hinnant91e2f262010-12-07 20:46:14932 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:21933 _Tp fetch_add(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT
Richard Smith6186c7f2012-04-11 18:55:46934 {return __c11_atomic_fetch_add(&this->__a_, __op, __m);}
Howard Hinnant91e2f262010-12-07 20:46:14935 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:21936 _Tp fetch_sub(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
Richard Smith6186c7f2012-04-11 18:55:46937 {return __c11_atomic_fetch_sub(&this->__a_, __op, __m);}
Howard Hinnant91e2f262010-12-07 20:46:14938 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:21939 _Tp fetch_sub(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT
Richard Smith6186c7f2012-04-11 18:55:46940 {return __c11_atomic_fetch_sub(&this->__a_, __op, __m);}
Howard Hinnant91e2f262010-12-07 20:46:14941 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:21942 _Tp fetch_and(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
Richard Smith6186c7f2012-04-11 18:55:46943 {return __c11_atomic_fetch_and(&this->__a_, __op, __m);}
Howard Hinnant91e2f262010-12-07 20:46:14944 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:21945 _Tp fetch_and(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT
Richard Smith6186c7f2012-04-11 18:55:46946 {return __c11_atomic_fetch_and(&this->__a_, __op, __m);}
Howard Hinnant91e2f262010-12-07 20:46:14947 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:21948 _Tp fetch_or(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
Richard Smith6186c7f2012-04-11 18:55:46949 {return __c11_atomic_fetch_or(&this->__a_, __op, __m);}
Howard Hinnant91e2f262010-12-07 20:46:14950 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:21951 _Tp fetch_or(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT
Richard Smith6186c7f2012-04-11 18:55:46952 {return __c11_atomic_fetch_or(&this->__a_, __op, __m);}
Howard Hinnant91e2f262010-12-07 20:46:14953 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:21954 _Tp fetch_xor(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
Richard Smith6186c7f2012-04-11 18:55:46955 {return __c11_atomic_fetch_xor(&this->__a_, __op, __m);}
Howard Hinnant91e2f262010-12-07 20:46:14956 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:21957 _Tp fetch_xor(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT
Richard Smith6186c7f2012-04-11 18:55:46958 {return __c11_atomic_fetch_xor(&this->__a_, __op, __m);}
Howard Hinnant91e2f262010-12-07 20:46:14959
960 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:21961 _Tp operator++(int) volatile _NOEXCEPT {return fetch_add(_Tp(1));}
Howard Hinnant91e2f262010-12-07 20:46:14962 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:21963 _Tp operator++(int) _NOEXCEPT {return fetch_add(_Tp(1));}
Howard Hinnant91e2f262010-12-07 20:46:14964 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:21965 _Tp operator--(int) volatile _NOEXCEPT {return fetch_sub(_Tp(1));}
Howard Hinnant91e2f262010-12-07 20:46:14966 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:21967 _Tp operator--(int) _NOEXCEPT {return fetch_sub(_Tp(1));}
Howard Hinnant91e2f262010-12-07 20:46:14968 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:21969 _Tp operator++() volatile _NOEXCEPT {return fetch_add(_Tp(1)) + _Tp(1);}
Howard Hinnant91e2f262010-12-07 20:46:14970 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:21971 _Tp operator++() _NOEXCEPT {return fetch_add(_Tp(1)) + _Tp(1);}
Howard Hinnant91e2f262010-12-07 20:46:14972 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:21973 _Tp operator--() volatile _NOEXCEPT {return fetch_sub(_Tp(1)) - _Tp(1);}
Howard Hinnant91e2f262010-12-07 20:46:14974 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:21975 _Tp operator--() _NOEXCEPT {return fetch_sub(_Tp(1)) - _Tp(1);}
Howard Hinnant91e2f262010-12-07 20:46:14976 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:21977 _Tp operator+=(_Tp __op) volatile _NOEXCEPT {return fetch_add(__op) + __op;}
Howard Hinnant91e2f262010-12-07 20:46:14978 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:21979 _Tp operator+=(_Tp __op) _NOEXCEPT {return fetch_add(__op) + __op;}
Howard Hinnant91e2f262010-12-07 20:46:14980 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:21981 _Tp operator-=(_Tp __op) volatile _NOEXCEPT {return fetch_sub(__op) - __op;}
Howard Hinnant91e2f262010-12-07 20:46:14982 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:21983 _Tp operator-=(_Tp __op) _NOEXCEPT {return fetch_sub(__op) - __op;}
Howard Hinnant91e2f262010-12-07 20:46:14984 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:21985 _Tp operator&=(_Tp __op) volatile _NOEXCEPT {return fetch_and(__op) & __op;}
Howard Hinnant91e2f262010-12-07 20:46:14986 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:21987 _Tp operator&=(_Tp __op) _NOEXCEPT {return fetch_and(__op) & __op;}
Howard Hinnant91e2f262010-12-07 20:46:14988 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:21989 _Tp operator|=(_Tp __op) volatile _NOEXCEPT {return fetch_or(__op) | __op;}
Howard Hinnant91e2f262010-12-07 20:46:14990 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:21991 _Tp operator|=(_Tp __op) _NOEXCEPT {return fetch_or(__op) | __op;}
Howard Hinnant91e2f262010-12-07 20:46:14992 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:21993 _Tp operator^=(_Tp __op) volatile _NOEXCEPT {return fetch_xor(__op) ^ __op;}
Howard Hinnant91e2f262010-12-07 20:46:14994 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:21995 _Tp operator^=(_Tp __op) _NOEXCEPT {return fetch_xor(__op) ^ __op;}
Howard Hinnant91e2f262010-12-07 20:46:14996};
997
998// atomic<T>
999
1000template <class _Tp>
1001struct atomic
1002 : public __atomic_base<_Tp>
1003{
1004 typedef __atomic_base<_Tp> __base;
1005 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant74f4da72013-05-02 20:18:431006 atomic() _NOEXCEPT _LIBCPP_DEFAULT
Howard Hinnant91e2f262010-12-07 20:46:141007 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211008 _LIBCPP_CONSTEXPR atomic(_Tp __d) _NOEXCEPT : __base(__d) {}
Howard Hinnantd2f6afb2010-12-07 23:24:411009
1010 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211011 _Tp operator=(_Tp __d) volatile _NOEXCEPT
Howard Hinnantd2f6afb2010-12-07 23:24:411012 {__base::store(__d); return __d;}
1013 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211014 _Tp operator=(_Tp __d) _NOEXCEPT
Howard Hinnantd2f6afb2010-12-07 23:24:411015 {__base::store(__d); return __d;}
Howard Hinnant91e2f262010-12-07 20:46:141016};
1017
1018// atomic<T*>
1019
1020template <class _Tp>
1021struct atomic<_Tp*>
1022 : public __atomic_base<_Tp*>
1023{
Howard Hinnantd2f6afb2010-12-07 23:24:411024 typedef __atomic_base<_Tp*> __base;
Howard Hinnant91e2f262010-12-07 20:46:141025 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant74f4da72013-05-02 20:18:431026 atomic() _NOEXCEPT _LIBCPP_DEFAULT
Howard Hinnant91e2f262010-12-07 20:46:141027 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211028 _LIBCPP_CONSTEXPR atomic(_Tp* __d) _NOEXCEPT : __base(__d) {}
Howard Hinnant91e2f262010-12-07 20:46:141029
1030 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211031 _Tp* operator=(_Tp* __d) volatile _NOEXCEPT
Howard Hinnantd2f6afb2010-12-07 23:24:411032 {__base::store(__d); return __d;}
1033 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211034 _Tp* operator=(_Tp* __d) _NOEXCEPT
Howard Hinnantd2f6afb2010-12-07 23:24:411035 {__base::store(__d); return __d;}
1036
1037 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant91e2f262010-12-07 20:46:141038 _Tp* fetch_add(ptrdiff_t __op, memory_order __m = memory_order_seq_cst)
Howard Hinnant300c67a2012-04-11 20:14:211039 volatile _NOEXCEPT
Richard Smith6186c7f2012-04-11 18:55:461040 {return __c11_atomic_fetch_add(&this->__a_, __op, __m);}
Howard Hinnant91e2f262010-12-07 20:46:141041 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211042 _Tp* fetch_add(ptrdiff_t __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT
Richard Smith6186c7f2012-04-11 18:55:461043 {return __c11_atomic_fetch_add(&this->__a_, __op, __m);}
Howard Hinnant91e2f262010-12-07 20:46:141044 _LIBCPP_INLINE_VISIBILITY
1045 _Tp* fetch_sub(ptrdiff_t __op, memory_order __m = memory_order_seq_cst)
Howard Hinnant300c67a2012-04-11 20:14:211046 volatile _NOEXCEPT
Richard Smith6186c7f2012-04-11 18:55:461047 {return __c11_atomic_fetch_sub(&this->__a_, __op, __m);}
Howard Hinnant91e2f262010-12-07 20:46:141048 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211049 _Tp* fetch_sub(ptrdiff_t __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT
Richard Smith6186c7f2012-04-11 18:55:461050 {return __c11_atomic_fetch_sub(&this->__a_, __op, __m);}
Howard Hinnant91e2f262010-12-07 20:46:141051
1052 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211053 _Tp* operator++(int) volatile _NOEXCEPT {return fetch_add(1);}
Howard Hinnant91e2f262010-12-07 20:46:141054 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211055 _Tp* operator++(int) _NOEXCEPT {return fetch_add(1);}
Howard Hinnant91e2f262010-12-07 20:46:141056 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211057 _Tp* operator--(int) volatile _NOEXCEPT {return fetch_sub(1);}
Howard Hinnant91e2f262010-12-07 20:46:141058 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211059 _Tp* operator--(int) _NOEXCEPT {return fetch_sub(1);}
Howard Hinnant91e2f262010-12-07 20:46:141060 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211061 _Tp* operator++() volatile _NOEXCEPT {return fetch_add(1) + 1;}
Howard Hinnant91e2f262010-12-07 20:46:141062 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211063 _Tp* operator++() _NOEXCEPT {return fetch_add(1) + 1;}
Howard Hinnant91e2f262010-12-07 20:46:141064 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211065 _Tp* operator--() volatile _NOEXCEPT {return fetch_sub(1) - 1;}
Howard Hinnant91e2f262010-12-07 20:46:141066 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211067 _Tp* operator--() _NOEXCEPT {return fetch_sub(1) - 1;}
Howard Hinnant91e2f262010-12-07 20:46:141068 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211069 _Tp* operator+=(ptrdiff_t __op) volatile _NOEXCEPT {return fetch_add(__op) + __op;}
Howard Hinnant91e2f262010-12-07 20:46:141070 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211071 _Tp* operator+=(ptrdiff_t __op) _NOEXCEPT {return fetch_add(__op) + __op;}
Howard Hinnant91e2f262010-12-07 20:46:141072 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211073 _Tp* operator-=(ptrdiff_t __op) volatile _NOEXCEPT {return fetch_sub(__op) - __op;}
Howard Hinnant91e2f262010-12-07 20:46:141074 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211075 _Tp* operator-=(ptrdiff_t __op) _NOEXCEPT {return fetch_sub(__op) - __op;}
Howard Hinnant91e2f262010-12-07 20:46:141076};
Howard Hinnant4777bf22010-12-06 23:10:081077
1078// atomic_is_lock_free
1079
1080template <class _Tp>
1081inline _LIBCPP_INLINE_VISIBILITY
1082bool
Howard Hinnant300c67a2012-04-11 20:14:211083atomic_is_lock_free(const volatile atomic<_Tp>* __o) _NOEXCEPT
Howard Hinnant4777bf22010-12-06 23:10:081084{
Howard Hinnant91e2f262010-12-07 20:46:141085 return __o->is_lock_free();
Howard Hinnant4777bf22010-12-06 23:10:081086}
1087
1088template <class _Tp>
1089inline _LIBCPP_INLINE_VISIBILITY
1090bool
Howard Hinnant300c67a2012-04-11 20:14:211091atomic_is_lock_free(const atomic<_Tp>* __o) _NOEXCEPT
Howard Hinnant4777bf22010-12-06 23:10:081092{
Howard Hinnant91e2f262010-12-07 20:46:141093 return __o->is_lock_free();
Howard Hinnant4777bf22010-12-06 23:10:081094}
1095
1096// atomic_init
1097
1098template <class _Tp>
1099inline _LIBCPP_INLINE_VISIBILITY
1100void
Howard Hinnant300c67a2012-04-11 20:14:211101atomic_init(volatile atomic<_Tp>* __o, _Tp __d) _NOEXCEPT
Howard Hinnant4777bf22010-12-06 23:10:081102{
Richard Smith6186c7f2012-04-11 18:55:461103 __c11_atomic_init(&__o->__a_, __d);
Howard Hinnant4777bf22010-12-06 23:10:081104}
1105
1106template <class _Tp>
1107inline _LIBCPP_INLINE_VISIBILITY
1108void
Howard Hinnant300c67a2012-04-11 20:14:211109atomic_init(atomic<_Tp>* __o, _Tp __d) _NOEXCEPT
Howard Hinnant4777bf22010-12-06 23:10:081110{
Richard Smith6186c7f2012-04-11 18:55:461111 __c11_atomic_init(&__o->__a_, __d);
Howard Hinnant4777bf22010-12-06 23:10:081112}
1113
1114// atomic_store
1115
1116template <class _Tp>
1117inline _LIBCPP_INLINE_VISIBILITY
1118void
Howard Hinnant300c67a2012-04-11 20:14:211119atomic_store(volatile atomic<_Tp>* __o, _Tp __d) _NOEXCEPT
Howard Hinnant4777bf22010-12-06 23:10:081120{
Howard Hinnant91e2f262010-12-07 20:46:141121 __o->store(__d);
Howard Hinnant4777bf22010-12-06 23:10:081122}
1123
1124template <class _Tp>
1125inline _LIBCPP_INLINE_VISIBILITY
1126void
Howard Hinnant300c67a2012-04-11 20:14:211127atomic_store(atomic<_Tp>* __o, _Tp __d) _NOEXCEPT
Howard Hinnant4777bf22010-12-06 23:10:081128{
Howard Hinnant91e2f262010-12-07 20:46:141129 __o->store(__d);
Howard Hinnant4777bf22010-12-06 23:10:081130}
1131
1132// atomic_store_explicit
1133
1134template <class _Tp>
1135inline _LIBCPP_INLINE_VISIBILITY
1136void
Howard Hinnant300c67a2012-04-11 20:14:211137atomic_store_explicit(volatile atomic<_Tp>* __o, _Tp __d, memory_order __m) _NOEXCEPT
Howard Hinnant4777bf22010-12-06 23:10:081138{
Howard Hinnant91e2f262010-12-07 20:46:141139 __o->store(__d, __m);
Howard Hinnant4777bf22010-12-06 23:10:081140}
1141
1142template <class _Tp>
1143inline _LIBCPP_INLINE_VISIBILITY
1144void
Howard Hinnant300c67a2012-04-11 20:14:211145atomic_store_explicit(atomic<_Tp>* __o, _Tp __d, memory_order __m) _NOEXCEPT
Howard Hinnant4777bf22010-12-06 23:10:081146{
Howard Hinnant91e2f262010-12-07 20:46:141147 __o->store(__d, __m);
Howard Hinnant4777bf22010-12-06 23:10:081148}
1149
1150// atomic_load
1151
1152template <class _Tp>
1153inline _LIBCPP_INLINE_VISIBILITY
1154_Tp
Howard Hinnant300c67a2012-04-11 20:14:211155atomic_load(const volatile atomic<_Tp>* __o) _NOEXCEPT
Howard Hinnant4777bf22010-12-06 23:10:081156{
Howard Hinnant91e2f262010-12-07 20:46:141157 return __o->load();
Howard Hinnant4777bf22010-12-06 23:10:081158}
1159
1160template <class _Tp>
1161inline _LIBCPP_INLINE_VISIBILITY
1162_Tp
Howard Hinnant300c67a2012-04-11 20:14:211163atomic_load(const atomic<_Tp>* __o) _NOEXCEPT
Howard Hinnant4777bf22010-12-06 23:10:081164{
Howard Hinnant91e2f262010-12-07 20:46:141165 return __o->load();
Howard Hinnant4777bf22010-12-06 23:10:081166}
1167
1168// atomic_load_explicit
1169
1170template <class _Tp>
1171inline _LIBCPP_INLINE_VISIBILITY
1172_Tp
Howard Hinnant300c67a2012-04-11 20:14:211173atomic_load_explicit(const volatile atomic<_Tp>* __o, memory_order __m) _NOEXCEPT
Howard Hinnant4777bf22010-12-06 23:10:081174{
Howard Hinnant91e2f262010-12-07 20:46:141175 return __o->load(__m);
Howard Hinnant4777bf22010-12-06 23:10:081176}
1177
1178template <class _Tp>
1179inline _LIBCPP_INLINE_VISIBILITY
1180_Tp
Howard Hinnant300c67a2012-04-11 20:14:211181atomic_load_explicit(const atomic<_Tp>* __o, memory_order __m) _NOEXCEPT
Howard Hinnant4777bf22010-12-06 23:10:081182{
Howard Hinnant91e2f262010-12-07 20:46:141183 return __o->load(__m);
Howard Hinnant4777bf22010-12-06 23:10:081184}
1185
1186// atomic_exchange
1187
1188template <class _Tp>
1189inline _LIBCPP_INLINE_VISIBILITY
1190_Tp
Howard Hinnant300c67a2012-04-11 20:14:211191atomic_exchange(volatile atomic<_Tp>* __o, _Tp __d) _NOEXCEPT
Howard Hinnant4777bf22010-12-06 23:10:081192{
Howard Hinnant91e2f262010-12-07 20:46:141193 return __o->exchange(__d);
Howard Hinnant4777bf22010-12-06 23:10:081194}
1195
1196template <class _Tp>
1197inline _LIBCPP_INLINE_VISIBILITY
1198_Tp
Howard Hinnant300c67a2012-04-11 20:14:211199atomic_exchange(atomic<_Tp>* __o, _Tp __d) _NOEXCEPT
Howard Hinnant4777bf22010-12-06 23:10:081200{
Howard Hinnant91e2f262010-12-07 20:46:141201 return __o->exchange(__d);
Howard Hinnant4777bf22010-12-06 23:10:081202}
1203
1204// atomic_exchange_explicit
1205
1206template <class _Tp>
1207inline _LIBCPP_INLINE_VISIBILITY
1208_Tp
Howard Hinnant300c67a2012-04-11 20:14:211209atomic_exchange_explicit(volatile atomic<_Tp>* __o, _Tp __d, memory_order __m) _NOEXCEPT
Howard Hinnant4777bf22010-12-06 23:10:081210{
Howard Hinnant91e2f262010-12-07 20:46:141211 return __o->exchange(__d, __m);
Howard Hinnant4777bf22010-12-06 23:10:081212}
1213
1214template <class _Tp>
1215inline _LIBCPP_INLINE_VISIBILITY
1216_Tp
Howard Hinnant300c67a2012-04-11 20:14:211217atomic_exchange_explicit(atomic<_Tp>* __o, _Tp __d, memory_order __m) _NOEXCEPT
Howard Hinnant4777bf22010-12-06 23:10:081218{
Howard Hinnant91e2f262010-12-07 20:46:141219 return __o->exchange(__d, __m);
Howard Hinnant4777bf22010-12-06 23:10:081220}
1221
1222// atomic_compare_exchange_weak
1223
1224template <class _Tp>
1225inline _LIBCPP_INLINE_VISIBILITY
1226bool
Howard Hinnant300c67a2012-04-11 20:14:211227atomic_compare_exchange_weak(volatile atomic<_Tp>* __o, _Tp* __e, _Tp __d) _NOEXCEPT
Howard Hinnant4777bf22010-12-06 23:10:081228{
Howard Hinnant91e2f262010-12-07 20:46:141229 return __o->compare_exchange_weak(*__e, __d);
Howard Hinnant4777bf22010-12-06 23:10:081230}
1231
1232template <class _Tp>
1233inline _LIBCPP_INLINE_VISIBILITY
1234bool
Howard Hinnant300c67a2012-04-11 20:14:211235atomic_compare_exchange_weak(atomic<_Tp>* __o, _Tp* __e, _Tp __d) _NOEXCEPT
Howard Hinnant4777bf22010-12-06 23:10:081236{
Howard Hinnant91e2f262010-12-07 20:46:141237 return __o->compare_exchange_weak(*__e, __d);
Howard Hinnant4777bf22010-12-06 23:10:081238}
1239
1240// atomic_compare_exchange_strong
1241
1242template <class _Tp>
1243inline _LIBCPP_INLINE_VISIBILITY
1244bool
Howard Hinnant300c67a2012-04-11 20:14:211245atomic_compare_exchange_strong(volatile atomic<_Tp>* __o, _Tp* __e, _Tp __d) _NOEXCEPT
Howard Hinnant4777bf22010-12-06 23:10:081246{
Howard Hinnant91e2f262010-12-07 20:46:141247 return __o->compare_exchange_strong(*__e, __d);
Howard Hinnant4777bf22010-12-06 23:10:081248}
1249
1250template <class _Tp>
1251inline _LIBCPP_INLINE_VISIBILITY
1252bool
Howard Hinnant300c67a2012-04-11 20:14:211253atomic_compare_exchange_strong(atomic<_Tp>* __o, _Tp* __e, _Tp __d) _NOEXCEPT
Howard Hinnant4777bf22010-12-06 23:10:081254{
Howard Hinnant91e2f262010-12-07 20:46:141255 return __o->compare_exchange_strong(*__e, __d);
Howard Hinnant4777bf22010-12-06 23:10:081256}
1257
1258// atomic_compare_exchange_weak_explicit
1259
1260template <class _Tp>
1261inline _LIBCPP_INLINE_VISIBILITY
1262bool
1263atomic_compare_exchange_weak_explicit(volatile atomic<_Tp>* __o, _Tp* __e,
1264 _Tp __d,
Howard Hinnant300c67a2012-04-11 20:14:211265 memory_order __s, memory_order __f) _NOEXCEPT
Howard Hinnant4777bf22010-12-06 23:10:081266{
Howard Hinnant91e2f262010-12-07 20:46:141267 return __o->compare_exchange_weak(*__e, __d, __s, __f);
Howard Hinnant4777bf22010-12-06 23:10:081268}
1269
1270template <class _Tp>
1271inline _LIBCPP_INLINE_VISIBILITY
1272bool
1273atomic_compare_exchange_weak_explicit(atomic<_Tp>* __o, _Tp* __e, _Tp __d,
Howard Hinnant300c67a2012-04-11 20:14:211274 memory_order __s, memory_order __f) _NOEXCEPT
Howard Hinnant4777bf22010-12-06 23:10:081275{
Howard Hinnant91e2f262010-12-07 20:46:141276 return __o->compare_exchange_weak(*__e, __d, __s, __f);
Howard Hinnant4777bf22010-12-06 23:10:081277}
1278
1279// atomic_compare_exchange_strong_explicit
1280
1281template <class _Tp>
1282inline _LIBCPP_INLINE_VISIBILITY
1283bool
1284atomic_compare_exchange_strong_explicit(volatile atomic<_Tp>* __o,
1285 _Tp* __e, _Tp __d,
Howard Hinnant300c67a2012-04-11 20:14:211286 memory_order __s, memory_order __f) _NOEXCEPT
Howard Hinnant4777bf22010-12-06 23:10:081287{
Howard Hinnant91e2f262010-12-07 20:46:141288 return __o->compare_exchange_strong(*__e, __d, __s, __f);
Howard Hinnant4777bf22010-12-06 23:10:081289}
1290
1291template <class _Tp>
1292inline _LIBCPP_INLINE_VISIBILITY
1293bool
1294atomic_compare_exchange_strong_explicit(atomic<_Tp>* __o, _Tp* __e,
1295 _Tp __d,
Howard Hinnant300c67a2012-04-11 20:14:211296 memory_order __s, memory_order __f) _NOEXCEPT
Howard Hinnant4777bf22010-12-06 23:10:081297{
Howard Hinnant91e2f262010-12-07 20:46:141298 return __o->compare_exchange_strong(*__e, __d, __s, __f);
Howard Hinnant4777bf22010-12-06 23:10:081299}
1300
Howard Hinnant91e2f262010-12-07 20:46:141301// atomic_fetch_add
Howard Hinnant4777bf22010-12-06 23:10:081302
1303template <class _Tp>
Howard Hinnant91e2f262010-12-07 20:46:141304inline _LIBCPP_INLINE_VISIBILITY
1305typename enable_if
1306<
1307 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1308 _Tp
1309>::type
Howard Hinnant300c67a2012-04-11 20:14:211310atomic_fetch_add(volatile atomic<_Tp>* __o, _Tp __op) _NOEXCEPT
Howard Hinnant4777bf22010-12-06 23:10:081311{
Howard Hinnant91e2f262010-12-07 20:46:141312 return __o->fetch_add(__op);
1313}
Howard Hinnant4777bf22010-12-06 23:10:081314
Howard Hinnant91e2f262010-12-07 20:46:141315template <class _Tp>
1316inline _LIBCPP_INLINE_VISIBILITY
1317typename enable_if
1318<
1319 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1320 _Tp
1321>::type
Howard Hinnant300c67a2012-04-11 20:14:211322atomic_fetch_add(atomic<_Tp>* __o, _Tp __op) _NOEXCEPT
Howard Hinnant91e2f262010-12-07 20:46:141323{
1324 return __o->fetch_add(__op);
1325}
Howard Hinnant4777bf22010-12-06 23:10:081326
Howard Hinnant91e2f262010-12-07 20:46:141327template <class _Tp>
1328inline _LIBCPP_INLINE_VISIBILITY
1329_Tp*
Howard Hinnant300c67a2012-04-11 20:14:211330atomic_fetch_add(volatile atomic<_Tp*>* __o, ptrdiff_t __op) _NOEXCEPT
Howard Hinnant91e2f262010-12-07 20:46:141331{
1332 return __o->fetch_add(__op);
1333}
1334
1335template <class _Tp>
1336inline _LIBCPP_INLINE_VISIBILITY
1337_Tp*
Howard Hinnant300c67a2012-04-11 20:14:211338atomic_fetch_add(atomic<_Tp*>* __o, ptrdiff_t __op) _NOEXCEPT
Howard Hinnant91e2f262010-12-07 20:46:141339{
1340 return __o->fetch_add(__op);
1341}
1342
1343// atomic_fetch_add_explicit
1344
1345template <class _Tp>
1346inline _LIBCPP_INLINE_VISIBILITY
1347typename enable_if
1348<
1349 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1350 _Tp
1351>::type
Howard Hinnant300c67a2012-04-11 20:14:211352atomic_fetch_add_explicit(volatile atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT
Howard Hinnant91e2f262010-12-07 20:46:141353{
1354 return __o->fetch_add(__op, __m);
1355}
1356
1357template <class _Tp>
1358inline _LIBCPP_INLINE_VISIBILITY
1359typename enable_if
1360<
1361 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1362 _Tp
1363>::type
Howard Hinnant300c67a2012-04-11 20:14:211364atomic_fetch_add_explicit(atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT
Howard Hinnant91e2f262010-12-07 20:46:141365{
1366 return __o->fetch_add(__op, __m);
1367}
1368
1369template <class _Tp>
1370inline _LIBCPP_INLINE_VISIBILITY
1371_Tp*
1372atomic_fetch_add_explicit(volatile atomic<_Tp*>* __o, ptrdiff_t __op,
Howard Hinnant300c67a2012-04-11 20:14:211373 memory_order __m) _NOEXCEPT
Howard Hinnant91e2f262010-12-07 20:46:141374{
1375 return __o->fetch_add(__op, __m);
1376}
1377
1378template <class _Tp>
1379inline _LIBCPP_INLINE_VISIBILITY
1380_Tp*
Howard Hinnant300c67a2012-04-11 20:14:211381atomic_fetch_add_explicit(atomic<_Tp*>* __o, ptrdiff_t __op, memory_order __m) _NOEXCEPT
Howard Hinnant91e2f262010-12-07 20:46:141382{
1383 return __o->fetch_add(__op, __m);
1384}
1385
1386// atomic_fetch_sub
1387
1388template <class _Tp>
1389inline _LIBCPP_INLINE_VISIBILITY
1390typename enable_if
1391<
1392 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1393 _Tp
1394>::type
Howard Hinnant300c67a2012-04-11 20:14:211395atomic_fetch_sub(volatile atomic<_Tp>* __o, _Tp __op) _NOEXCEPT
Howard Hinnant91e2f262010-12-07 20:46:141396{
1397 return __o->fetch_sub(__op);
1398}
1399
1400template <class _Tp>
1401inline _LIBCPP_INLINE_VISIBILITY
1402typename enable_if
1403<
1404 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1405 _Tp
1406>::type
Howard Hinnant300c67a2012-04-11 20:14:211407atomic_fetch_sub(atomic<_Tp>* __o, _Tp __op) _NOEXCEPT
Howard Hinnant91e2f262010-12-07 20:46:141408{
1409 return __o->fetch_sub(__op);
1410}
1411
1412template <class _Tp>
1413inline _LIBCPP_INLINE_VISIBILITY
1414_Tp*
Howard Hinnant300c67a2012-04-11 20:14:211415atomic_fetch_sub(volatile atomic<_Tp*>* __o, ptrdiff_t __op) _NOEXCEPT
Howard Hinnant91e2f262010-12-07 20:46:141416{
1417 return __o->fetch_sub(__op);
1418}
1419
1420template <class _Tp>
1421inline _LIBCPP_INLINE_VISIBILITY
1422_Tp*
Howard Hinnant300c67a2012-04-11 20:14:211423atomic_fetch_sub(atomic<_Tp*>* __o, ptrdiff_t __op) _NOEXCEPT
Howard Hinnant91e2f262010-12-07 20:46:141424{
1425 return __o->fetch_sub(__op);
1426}
1427
1428// atomic_fetch_sub_explicit
1429
1430template <class _Tp>
1431inline _LIBCPP_INLINE_VISIBILITY
1432typename enable_if
1433<
1434 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1435 _Tp
1436>::type
Howard Hinnant300c67a2012-04-11 20:14:211437atomic_fetch_sub_explicit(volatile atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT
Howard Hinnant91e2f262010-12-07 20:46:141438{
1439 return __o->fetch_sub(__op, __m);
1440}
1441
1442template <class _Tp>
1443inline _LIBCPP_INLINE_VISIBILITY
1444typename enable_if
1445<
1446 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1447 _Tp
1448>::type
Howard Hinnant300c67a2012-04-11 20:14:211449atomic_fetch_sub_explicit(atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT
Howard Hinnant91e2f262010-12-07 20:46:141450{
1451 return __o->fetch_sub(__op, __m);
1452}
1453
1454template <class _Tp>
1455inline _LIBCPP_INLINE_VISIBILITY
1456_Tp*
1457atomic_fetch_sub_explicit(volatile atomic<_Tp*>* __o, ptrdiff_t __op,
Howard Hinnant300c67a2012-04-11 20:14:211458 memory_order __m) _NOEXCEPT
Howard Hinnant91e2f262010-12-07 20:46:141459{
1460 return __o->fetch_sub(__op, __m);
1461}
1462
1463template <class _Tp>
1464inline _LIBCPP_INLINE_VISIBILITY
1465_Tp*
Howard Hinnant300c67a2012-04-11 20:14:211466atomic_fetch_sub_explicit(atomic<_Tp*>* __o, ptrdiff_t __op, memory_order __m) _NOEXCEPT
Howard Hinnant91e2f262010-12-07 20:46:141467{
1468 return __o->fetch_sub(__op, __m);
1469}
1470
1471// atomic_fetch_and
1472
1473template <class _Tp>
1474inline _LIBCPP_INLINE_VISIBILITY
1475typename enable_if
1476<
1477 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1478 _Tp
1479>::type
Howard Hinnant300c67a2012-04-11 20:14:211480atomic_fetch_and(volatile atomic<_Tp>* __o, _Tp __op) _NOEXCEPT
Howard Hinnant91e2f262010-12-07 20:46:141481{
1482 return __o->fetch_and(__op);
1483}
1484
1485template <class _Tp>
1486inline _LIBCPP_INLINE_VISIBILITY
1487typename enable_if
1488<
1489 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1490 _Tp
1491>::type
Howard Hinnant300c67a2012-04-11 20:14:211492atomic_fetch_and(atomic<_Tp>* __o, _Tp __op) _NOEXCEPT
Howard Hinnant91e2f262010-12-07 20:46:141493{
1494 return __o->fetch_and(__op);
1495}
1496
1497// atomic_fetch_and_explicit
1498
1499template <class _Tp>
1500inline _LIBCPP_INLINE_VISIBILITY
1501typename enable_if
1502<
1503 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1504 _Tp
1505>::type
Howard Hinnant300c67a2012-04-11 20:14:211506atomic_fetch_and_explicit(volatile atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT
Howard Hinnant91e2f262010-12-07 20:46:141507{
1508 return __o->fetch_and(__op, __m);
1509}
1510
1511template <class _Tp>
1512inline _LIBCPP_INLINE_VISIBILITY
1513typename enable_if
1514<
1515 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1516 _Tp
1517>::type
Howard Hinnant300c67a2012-04-11 20:14:211518atomic_fetch_and_explicit(atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT
Howard Hinnant91e2f262010-12-07 20:46:141519{
1520 return __o->fetch_and(__op, __m);
1521}
1522
1523// atomic_fetch_or
1524
1525template <class _Tp>
1526inline _LIBCPP_INLINE_VISIBILITY
1527typename enable_if
1528<
1529 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1530 _Tp
1531>::type
Howard Hinnant300c67a2012-04-11 20:14:211532atomic_fetch_or(volatile atomic<_Tp>* __o, _Tp __op) _NOEXCEPT
Howard Hinnant91e2f262010-12-07 20:46:141533{
1534 return __o->fetch_or(__op);
1535}
1536
1537template <class _Tp>
1538inline _LIBCPP_INLINE_VISIBILITY
1539typename enable_if
1540<
1541 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1542 _Tp
1543>::type
Howard Hinnant300c67a2012-04-11 20:14:211544atomic_fetch_or(atomic<_Tp>* __o, _Tp __op) _NOEXCEPT
Howard Hinnant91e2f262010-12-07 20:46:141545{
1546 return __o->fetch_or(__op);
1547}
1548
1549// atomic_fetch_or_explicit
1550
1551template <class _Tp>
1552inline _LIBCPP_INLINE_VISIBILITY
1553typename enable_if
1554<
1555 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1556 _Tp
1557>::type
Howard Hinnant300c67a2012-04-11 20:14:211558atomic_fetch_or_explicit(volatile atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT
Howard Hinnant91e2f262010-12-07 20:46:141559{
1560 return __o->fetch_or(__op, __m);
1561}
1562
1563template <class _Tp>
1564inline _LIBCPP_INLINE_VISIBILITY
1565typename enable_if
1566<
1567 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1568 _Tp
1569>::type
Howard Hinnant300c67a2012-04-11 20:14:211570atomic_fetch_or_explicit(atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT
Howard Hinnant91e2f262010-12-07 20:46:141571{
1572 return __o->fetch_or(__op, __m);
1573}
1574
1575// atomic_fetch_xor
1576
1577template <class _Tp>
1578inline _LIBCPP_INLINE_VISIBILITY
1579typename enable_if
1580<
1581 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1582 _Tp
1583>::type
Howard Hinnant300c67a2012-04-11 20:14:211584atomic_fetch_xor(volatile atomic<_Tp>* __o, _Tp __op) _NOEXCEPT
Howard Hinnant91e2f262010-12-07 20:46:141585{
1586 return __o->fetch_xor(__op);
1587}
1588
1589template <class _Tp>
1590inline _LIBCPP_INLINE_VISIBILITY
1591typename enable_if
1592<
1593 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1594 _Tp
1595>::type
Howard Hinnant300c67a2012-04-11 20:14:211596atomic_fetch_xor(atomic<_Tp>* __o, _Tp __op) _NOEXCEPT
Howard Hinnant91e2f262010-12-07 20:46:141597{
1598 return __o->fetch_xor(__op);
1599}
1600
1601// atomic_fetch_xor_explicit
1602
1603template <class _Tp>
1604inline _LIBCPP_INLINE_VISIBILITY
1605typename enable_if
1606<
1607 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1608 _Tp
1609>::type
Howard Hinnant300c67a2012-04-11 20:14:211610atomic_fetch_xor_explicit(volatile atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT
Howard Hinnant91e2f262010-12-07 20:46:141611{
1612 return __o->fetch_xor(__op, __m);
1613}
1614
1615template <class _Tp>
1616inline _LIBCPP_INLINE_VISIBILITY
1617typename enable_if
1618<
1619 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1620 _Tp
1621>::type
Howard Hinnant300c67a2012-04-11 20:14:211622atomic_fetch_xor_explicit(atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT
Howard Hinnant91e2f262010-12-07 20:46:141623{
1624 return __o->fetch_xor(__op, __m);
1625}
Howard Hinnant4777bf22010-12-06 23:10:081626
Howard Hinnant770d1c42010-12-08 17:20:281627// flag type and operations
1628
1629typedef struct atomic_flag
1630{
David Chisnall83b2c842011-12-19 11:44:201631 _Atomic(bool) __a_;
Howard Hinnant770d1c42010-12-08 17:20:281632
1633 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211634 bool test_and_set(memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
Richard Smith6186c7f2012-04-11 18:55:461635 {return __c11_atomic_exchange(&__a_, true, __m);}
Howard Hinnant770d1c42010-12-08 17:20:281636 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211637 bool test_and_set(memory_order __m = memory_order_seq_cst) _NOEXCEPT
Richard Smith6186c7f2012-04-11 18:55:461638 {return __c11_atomic_exchange(&__a_, true, __m);}
Howard Hinnant770d1c42010-12-08 17:20:281639 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211640 void clear(memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
Richard Smith6186c7f2012-04-11 18:55:461641 {__c11_atomic_store(&__a_, false, __m);}
Howard Hinnant770d1c42010-12-08 17:20:281642 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211643 void clear(memory_order __m = memory_order_seq_cst) _NOEXCEPT
Richard Smith6186c7f2012-04-11 18:55:461644 {__c11_atomic_store(&__a_, false, __m);}
Howard Hinnant770d1c42010-12-08 17:20:281645
1646 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant74f4da72013-05-02 20:18:431647#ifndef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
1648 atomic_flag() _NOEXCEPT = default;
1649#else
1650 atomic_flag() _NOEXCEPT : __a_() {}
1651#endif // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
1652
Howard Hinnant770d1c42010-12-08 17:20:281653 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211654 atomic_flag(bool __b) _NOEXCEPT : __a_(__b) {}
Howard Hinnant770d1c42010-12-08 17:20:281655
1656#ifndef _LIBCPP_HAS_NO_DELETED_FUNCTIONS
1657 atomic_flag(const atomic_flag&) = delete;
1658 atomic_flag& operator=(const atomic_flag&) = delete;
1659 atomic_flag& operator=(const atomic_flag&) volatile = delete;
1660#else // _LIBCPP_HAS_NO_DELETED_FUNCTIONS
1661private:
1662 atomic_flag(const atomic_flag&);
1663 atomic_flag& operator=(const atomic_flag&);
1664 atomic_flag& operator=(const atomic_flag&) volatile;
1665#endif // _LIBCPP_HAS_NO_DELETED_FUNCTIONS
1666} atomic_flag;
1667
1668inline _LIBCPP_INLINE_VISIBILITY
1669bool
Howard Hinnant300c67a2012-04-11 20:14:211670atomic_flag_test_and_set(volatile atomic_flag* __o) _NOEXCEPT
Howard Hinnant770d1c42010-12-08 17:20:281671{
1672 return __o->test_and_set();
1673}
1674
1675inline _LIBCPP_INLINE_VISIBILITY
1676bool
Howard Hinnant300c67a2012-04-11 20:14:211677atomic_flag_test_and_set(atomic_flag* __o) _NOEXCEPT
Howard Hinnant770d1c42010-12-08 17:20:281678{
1679 return __o->test_and_set();
1680}
1681
1682inline _LIBCPP_INLINE_VISIBILITY
1683bool
Howard Hinnant300c67a2012-04-11 20:14:211684atomic_flag_test_and_set_explicit(volatile atomic_flag* __o, memory_order __m) _NOEXCEPT
Howard Hinnant770d1c42010-12-08 17:20:281685{
1686 return __o->test_and_set(__m);
1687}
1688
1689inline _LIBCPP_INLINE_VISIBILITY
1690bool
Howard Hinnant300c67a2012-04-11 20:14:211691atomic_flag_test_and_set_explicit(atomic_flag* __o, memory_order __m) _NOEXCEPT
Howard Hinnant770d1c42010-12-08 17:20:281692{
1693 return __o->test_and_set(__m);
1694}
1695
1696inline _LIBCPP_INLINE_VISIBILITY
1697void
Howard Hinnant300c67a2012-04-11 20:14:211698atomic_flag_clear(volatile atomic_flag* __o) _NOEXCEPT
Howard Hinnant770d1c42010-12-08 17:20:281699{
1700 __o->clear();
1701}
1702
1703inline _LIBCPP_INLINE_VISIBILITY
1704void
Howard Hinnant300c67a2012-04-11 20:14:211705atomic_flag_clear(atomic_flag* __o) _NOEXCEPT
Howard Hinnant770d1c42010-12-08 17:20:281706{
1707 __o->clear();
1708}
1709
1710inline _LIBCPP_INLINE_VISIBILITY
1711void
Howard Hinnant300c67a2012-04-11 20:14:211712atomic_flag_clear_explicit(volatile atomic_flag* __o, memory_order __m) _NOEXCEPT
Howard Hinnant770d1c42010-12-08 17:20:281713{
1714 __o->clear(__m);
1715}
1716
1717inline _LIBCPP_INLINE_VISIBILITY
1718void
Howard Hinnant300c67a2012-04-11 20:14:211719atomic_flag_clear_explicit(atomic_flag* __o, memory_order __m) _NOEXCEPT
Howard Hinnant770d1c42010-12-08 17:20:281720{
1721 __o->clear(__m);
1722}
1723
1724// fences
1725
1726inline _LIBCPP_INLINE_VISIBILITY
1727void
Howard Hinnant300c67a2012-04-11 20:14:211728atomic_thread_fence(memory_order __m) _NOEXCEPT
Howard Hinnant770d1c42010-12-08 17:20:281729{
Richard Smith6186c7f2012-04-11 18:55:461730 __c11_atomic_thread_fence(__m);
Howard Hinnant770d1c42010-12-08 17:20:281731}
1732
1733inline _LIBCPP_INLINE_VISIBILITY
1734void
Howard Hinnant300c67a2012-04-11 20:14:211735atomic_signal_fence(memory_order __m) _NOEXCEPT
Howard Hinnant770d1c42010-12-08 17:20:281736{
Richard Smith6186c7f2012-04-11 18:55:461737 __c11_atomic_signal_fence(__m);
Howard Hinnant770d1c42010-12-08 17:20:281738}
1739
Howard Hinnantd2f6afb2010-12-07 23:24:411740// Atomics for standard typedef types
1741
Howard Hinnant6ae47052013-01-04 18:58:501742typedef atomic<bool> atomic_bool;
Howard Hinnantd2f6afb2010-12-07 23:24:411743typedef atomic<char> atomic_char;
1744typedef atomic<signed char> atomic_schar;
1745typedef atomic<unsigned char> atomic_uchar;
1746typedef atomic<short> atomic_short;
1747typedef atomic<unsigned short> atomic_ushort;
1748typedef atomic<int> atomic_int;
1749typedef atomic<unsigned int> atomic_uint;
1750typedef atomic<long> atomic_long;
1751typedef atomic<unsigned long> atomic_ulong;
1752typedef atomic<long long> atomic_llong;
1753typedef atomic<unsigned long long> atomic_ullong;
1754typedef atomic<char16_t> atomic_char16_t;
1755typedef atomic<char32_t> atomic_char32_t;
1756typedef atomic<wchar_t> atomic_wchar_t;
1757
1758typedef atomic<int_least8_t> atomic_int_least8_t;
1759typedef atomic<uint_least8_t> atomic_uint_least8_t;
1760typedef atomic<int_least16_t> atomic_int_least16_t;
1761typedef atomic<uint_least16_t> atomic_uint_least16_t;
1762typedef atomic<int_least32_t> atomic_int_least32_t;
1763typedef atomic<uint_least32_t> atomic_uint_least32_t;
1764typedef atomic<int_least64_t> atomic_int_least64_t;
1765typedef atomic<uint_least64_t> atomic_uint_least64_t;
1766
1767typedef atomic<int_fast8_t> atomic_int_fast8_t;
1768typedef atomic<uint_fast8_t> atomic_uint_fast8_t;
1769typedef atomic<int_fast16_t> atomic_int_fast16_t;
1770typedef atomic<uint_fast16_t> atomic_uint_fast16_t;
1771typedef atomic<int_fast32_t> atomic_int_fast32_t;
1772typedef atomic<uint_fast32_t> atomic_uint_fast32_t;
1773typedef atomic<int_fast64_t> atomic_int_fast64_t;
1774typedef atomic<uint_fast64_t> atomic_uint_fast64_t;
1775
1776typedef atomic<intptr_t> atomic_intptr_t;
1777typedef atomic<uintptr_t> atomic_uintptr_t;
1778typedef atomic<size_t> atomic_size_t;
1779typedef atomic<ptrdiff_t> atomic_ptrdiff_t;
1780typedef atomic<intmax_t> atomic_intmax_t;
1781typedef atomic<uintmax_t> atomic_uintmax_t;
1782
Howard Hinnant767ae2b2010-09-29 21:20:031783#define ATOMIC_FLAG_INIT {false}
Howard Hinnant611fdaf2010-10-04 18:52:541784#define ATOMIC_VAR_INIT(__v) {__v}
1785
Howard Hinnant7b9d6a82013-01-21 20:39:411786#define ATOMIC_BOOL_LOCK_FREE __GCC_ATOMIC_BOOL_LOCK_FREE
1787#define ATOMIC_CHAR_LOCK_FREE __GCC_ATOMIC_CHAR_LOCK_FREE
1788#define ATOMIC_CHAR16_T_LOCK_FREE __GCC_ATOMIC_CHAR16_T_LOCK_FREE
1789#define ATOMIC_CHAR32_T_LOCK_FREE __GCC_ATOMIC_CHAR32_T_LOCK_FREE
1790#define ATOMIC_WCHAR_T_LOCK_FREE __GCC_ATOMIC_WCHAR_T_LOCK_FREE
1791#define ATOMIC_SHORT_LOCK_FREE __GCC_ATOMIC_SHORT_LOCK_FREE
1792#define ATOMIC_INT_LOCK_FREE __GCC_ATOMIC_INT_LOCK_FREE
1793#define ATOMIC_LONG_LOCK_FREE __GCC_ATOMIC_LONG_LOCK_FREE
1794#define ATOMIC_LLONG_LOCK_FREE __GCC_ATOMIC_LLONG_LOCK_FREE
1795#define ATOMIC_POINTER_LOCK_FREE __GCC_ATOMIC_POINTER_LOCK_FREE
Howard Hinnant770d1c42010-12-08 17:20:281796
Howard Hinnant8f73c632010-09-27 21:17:381797_LIBCPP_END_NAMESPACE_STD
1798
Howard Hinnant8f73c632010-09-27 21:17:381799#endif // _LIBCPP_ATOMIC